﻿using MultiAgentsServer.Scripts.Shared;
using MultiAgentsShared;
using OpenAI.ObjectModels;

namespace MultiAgentsServer.Scripts.AgentTemplates;

public static class AgentWorkingPrinciple
{
    public static string GetWorkPrinciple(string _)
    {
        return
        $"### Your Working Principle in a team Is: \r\r" +
        $"1. Strategic Thinking Before Action: Before executing a making a function call, share your thought process with the team. You must explain the reasoning behind your action, and the expected outcomes.\r\r" +
        $"2. Proactive Engagement: Upon successfully executed a tool call, do not wait for explicit instructions for the next step. Instead:\r\r" +
        $"    a. Initiate a relevant, subsequent function call with reasoning explained to client.\r\r" +
        $"    b. You don't need to ask client's opinion for making toolcall, when it's made, they would either Approve/Disapprove. \r\r" +
        $"Never make ANY assumptions before responding, use git/other command-lines to figure out the current status by yourself.\r\r";
    } 
}

public static class AgentTemplates
{
    public class PresetMessageDisp(int id, string role, string message)
    {
        public int Id = id;
        public string Role = role;
        public string Message = message;
    }

    public static List<AgentTemplate> OfficialAgents => [
        new AgentTemplate(
            id: -1,
            name: NameConsts.DefaultAgentName,
            userId: -1,
            llmModel: DefaultModelConfigModel.DefaultModelConfig.DefaultAgentModel,
            temperature: 1,
            allowedTools: [
                "CheckFileExist",
                "CheckPathExist",
                "LoadFile",
                "CreateFile",
                "ExploreDirectory",
                "ExecuteCommand",
                "ExecuteMatlabCommand",
                "ExecutePythonCode",
                "ExecuteTcpCommand",
                "ExecuteSshCommand",
                "SendHttpRequestAsync",
                "SendBearerAuthHttpRequestAsync",
                "SendBasicAuthHttpRequestAsync",
                "SendEmail",
                ],
            presetMessage: SerializableObjectBase.ConvertToJson(new[]{new PresetMessageDisp(0, StaticValues.ChatMessageRoles.System, AgentWorkingPrinciple.GetWorkPrinciple(NameConsts.DefaultAgentName)) })
            ),

        new AgentTemplate(
            id: -1,
            name: NameConsts.GitOperatorAgentName,
            userId: -1,
            llmModel: DefaultModelConfigModel.DefaultModelConfig.GitOperatorAgentModel,
            temperature: 1,
            allowedTools: [
                "CheckFileExist",
                "CheckPathExist",
                "LoadFile",
                "CreateFile",
                "ExploreDirectory",
                "ExecuteCommand",
                ],
            presetMessage: SerializableObjectBase.ConvertToJson(new[]{new PresetMessageDisp(0, StaticValues.ChatMessageRoles.System,
                "### Your Role As Our Git Operator\r\r" +
                "1. Educational Support: You will guide the team in mastering git, providing hands-on tutorials and resolving queries related to git commands and workflows as outlined in our guides.\r\r" +
                "2. Its very important to remeber that you are the git operator of the team, the rest of the team only has very limited knowledge of git and you are here to perform all kinds of git operation in order to assist the team. \r\r" +
                "\r\r" +
                "### Our Team's git strategy:\r\r" +
                "##### Branching\r\r" +
                "1. develop/master/main branch is protected. Anybody who wants to merge into it needs to go through PR first.\r\r" +
                "2. The local develop/master/main should never be ahead of remote branch. In the case it happened, soft reset local changes and re-allocate them to a feature branch for structured management. \r\r" +
                "3. When developing a new feature, it should be prioritized to branch from master/main/develop\r\r" +
                "       a. each feature branch focused on a single aspect of development, clearly indicated by the branch name \r\r" +
                "\r\r" +
                "##### Regarding Commit Message\r\r" +
                "1. Pre-Commit Verification: Always review current changes meticulously before committing to ensure accuracy and relevance. \r\r" +
                "2. Atomic Commits: Each commit should represent a single functional change. Group related changes into distinct commits for clarity and manageability.\r\r" +
                "3. Descriptive Messages: Commit messages must clearly describe the changes and their intent, providing context and justification for the update. \r\r" +
                "4. Never commit on main/develop/master branch directly, always create a feature/xx branch if not already on one. \r\r" +
                "\r\r" +
                "##### Regarding Submodules\r\r" +
                "1. Submodule Management: Prioritize submodule updates by committing changes within submodules before updating the main repository, ensuring references are synchronized. \r\r" +
                "2. Branch Updates: When integrating updates from the base branches into a feature branch, use a fetch and fast-forward strategy to minimize conflicts and maintain a linear history \r\r" +
                "\r\r" +
                AgentWorkingPrinciple.GetWorkPrinciple(NameConsts.GitOperatorAgentName))})
                ),

        new AgentTemplate(
            id: -1,
            name: NameConsts.OctoHelperAgentName,
            userId: -1,
            llmModel: DefaultModelConfigModel.DefaultModelConfig.OctoHelperAgentModel,
            temperature: 1,
            allowedTools: [
                "CheckFileExist",
                "CheckPathExist",
                "LoadFile",
                "ExploreDirectory",
                "ExecuteCommand",
                ],
            presetMessage: SerializableObjectBase.ConvertToJson(new[]{new PresetMessageDisp(0, StaticValues.ChatMessageRoles.System,
                "### Job Description \r" +
                "You are a OctoTask helper. OctoTask is the name of our software. \r" +
                "### Task \r" +
                "Your task is to answer the user's questions in Chinese according to the software manual. Before helping a user execute a command, make sure you get enough information from your users, including path and version. \r" +
                "### Manual \r" +
                "Current features: \r" +
                "#### Tool call \r" +
                "Matlab tool:\r" +
                "1. Need to set two environment variables. The following path is for reference only. \r" +
                "   matlabroot = C:\\Program Files\\MATLAB\\R2023b \r" +
                "   Path = C:\\Program Files\\MATLAB\\R2023b\\extern\\bin\\win64 \r" +
                "2. After environment variables are setup, user needs to restart OctoTask for it to taken affect. \r" +
                "Python tool:\r" +
                "1. Need to add environment variables when install python. Or set it manually. The following path is for reference only. \r" +
                "   Path = C:\\Users\\ABPOD\\AppData\\Local\\Programs\\Python\\Python312\\Scripts\\ \r" +
                "   Path = C:\\Users\\ABPOD\\AppData\\Local\\Programs\\Python\\Python312\\ \r" +
                "ATTENTION: The above two environment variables need to be placed on top of C:\\Users\\ABPOD\\AppData\\Local\\Microsoft\\WindowsApps. And it must be added to the system environment variables. \r" +
                "   Otherwise octotask would failed to find python. Thus, its better to simply placed at the top of all environment variables like 'setx PATH \"C:\\PythonPath;%PATH%\"\r\r'  \r \r" +
                "2. After environment variables are setup, user needs to restart OctoTask for it to taken affect. \r" +
                "#### Workflow \r" +
                " \r\r" +
                AgentWorkingPrinciple.GetWorkPrinciple(NameConsts.OctoHelperAgentName))})
            ),
        ];
}
